<?php

/**
 * account actions.
 *
 * @package    aceptor
 * @subpackage account
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class accountActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
  
  }


   public function executeTestAsociateAccount(sfWebRequest $request)
  {

      $this->setLayout(false);
      $querydata = http_build_query(
            array(
                     md5('name')      => 'Cesar',
                     md5('lastName')  => 'Quevedo',
                     md5('practilId') => '27',
                     md5('email')     => 'lllcesarlll@hotmail.com',
                     md5('token')     => 'G1D2FC36VX78CGF7DA9SF84DA0SZZZ',
                     md5('paqueteid') => '10'
                 )
            );
       $json_string    = 'http://localhost/practil_aceptor/web/frontend_dev.php/account/asociateAccount?'.$querydata;

       $respuesta_servicio = file_get_contents($json_string);
       $decode             = json_decode($respuesta_servicio);
       $this->json_string  = $respuesta_servicio;



  }


  // metodo web service para ser comsumido desde practil
  public function executeAsociateAccount(sfWebRequest $request){

            
            $request->setRequestFormat('json');
            //parametos necesarios :
            $nombres    =  $request->getParameter(md5('name'));
            $apellido   =  $request->getParameter(md5('lastName'));
            $practilId  =  $request->getParameter(md5('practilId'));
            $email      =  $request->getParameter(md5('email'));
            $token      =  $request->getParameter(md5('token'));
            $paqueteid  =  $request->getParameter(md5('paqueteid'));

            $service    =  new serviceAceptor();
            $arrayRespt = $service->usersRegister($nombres,
                                             $apellido,
                                             $apellido,
                                             $email,
                                             'practil');

            if($arrayRespt['success'])
            {
                
                $arrayResptAsociate = $service->userAsociatePractilId($arrayRespt['object'], $practilId);
                if($arrayResptAsociate){
                       $servicePaquete = new servicePlanes($paqueteid);
                       $success = $servicePaquete->RegistarPaqueteAceptor($arrayRespt['object']->getId());
                       if($success['success'])
                       {
                           $this->message = 'exito';
                           return sfView::SUCCESS;
                       }
                       else
                       {
                            $this->message = 'RegistarPaqueteAceptor Error-'.$success['message'];
                            return sfView::ERROR;
                       }

                }
                else
                {
                    $this->message = 'userAsociatePractilId Error';
                    return sfView::ERROR;
                }
            }
            else
            {
                $this->message = 'usersRegister Error-'.$arrayRespt['message'];
                return sfView::ERROR;
            }
           

           

}




}
